package com.example.nacosconsumer.controller;


import com.example.nacosconsumer.server.ProviderFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RequestMapping("/api/consumer")
@RestController
@Slf4j
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    ProviderFeignService providerFeignService;


    @GetMapping
    public String test(){
        log.info("这是用的restTemplate方式服务之间的调用。通过负载均衡");
        return  restTemplate.getForObject("http://nacos-provider/api/provider",String.class);
    }

    @GetMapping("/test2")
    public String test2(){
        log.info("这是用的providerFeignService方式服务之间的调用。通过负载均衡");
        return  providerFeignService.selectMessage();
    }
}
